import java.math.BigInteger

/**
 *@ClassName RecursionDemo
 *
 *@Author ykx
 *@Date  2024/6/17 21:58
 *@Version 1.0
 */
fun main(args: Array<String>) {
    var num = 100000
    println(ollAdd(num, 0))
}

fun fact(num: BigInteger): BigInteger {
    return if (num == BigInteger.ONE) {
        BigInteger.ONE
    } else {
        num * fact(num - BigInteger.ONE)
    }
}

tailrec fun ollAdd(num: Int, result: Int): Int {
    println("第${num}次运算,结果是:$result")
    return if (num == 0) {
        return 1
    } else {
        return ollAdd(num - 1, result + num)
    }
}